package Tela;

public class AcaoPGExcluir extends AcaoPanelGrafo {

	public String executar(int x, int y) {
		PanelGrafo dono = getPanelGrafo();
		int totalItems = dono.qtosItems();
		ItemPanelGrafo item = null;
		dono.removerSelecionados();

		for (int i = 0; i < totalItems; i++) {
			item = dono.getItem(i);
			if (item.contido(x, y)) {

				ItemPGNoh noh = findNoh(x, y);
				int nun = noh.getArcosCompleto().size();
				for (int count = 0; count < nun; count++) {
					dono.removerItem((ItemPanelGrafo) noh.getArcos(count));
				}
				noh.removeTodosArcos();
				dono.removerItem(item);

				return "";
			}

		}
		return null;
	}

	private ItemPGNoh findNoh(int x, int y) {
		PanelGrafo pg = getPanelGrafo();
		int totalItems = pg.qtosItems();
		ItemPanelGrafo item;
		for (int i = 0; i < totalItems; i++) {
			item = pg.getItem(i);
			if (item instanceof ItemPGNoh && item.contido(x, y))
				return (ItemPGNoh) item;
		}
		return null;
	}

	public void encerrar(int x, int y) {
		;
	}

	public void mover(int x, int y) {

	}

	public void mudouAcao() {
	}
}
